import inquirer from 'inquirer'
import axios from 'axios'
import ora from 'ora'
import { execSync } from 'child_process'
const spinner = ora()


console.log(process.env);
inquirer.prompt([
    {
        type: 'list',
        name: '提交类型',
        message: '提交类型',
        default: 'feat',
        choices: [
            { name: 'feat', value: 'feat' },
            { name: 'fix', value: 'fix' },
            { name: 'test', value: 'test' },
        ]
    },
    {
        type: 'input',
        name: '项目信息',
        message: '项目信息',
    },
    {
        type: 'input',
        name: '提交信息',
        message: '提交信息',
    },
]).then((answers) => {
    if (answers['提交信息'] === '' || answers['项目信息'] === '') {
        spinner.fail('完善提交信息!')
        process.exit(0)
    }
    spinner.start()

    spinner.info('开始提交...')
    execSync(`git commit -m  ${answers['提交类型']}[${answers['项目信息']}]${answers['提交信息']}`)
    spinner.info('提交成功!')
    spinner.info('开始推送...')

    execSync(`git push`)
    spinner.info('推送成功!')

    let data = {
        message: answers['提交类型'] + `[${answers['项目信息']}]` + answers['提交信息'],
        timeStr: new Date().toLocaleString(),
        author: '喜喜喜'
    }
    spinner.info('开始存储1...')
    axios.post(
        // "http://127.0.0.1:3001/addMessage"
        'http://47.97.209.240:3001/addMessage'
        , data
    ).finally(() => {
        spinner.succeed('存储完毕!')
        process.exit(0)
    })










})








